<?php
/*
	用户端公共文件，访问用户端时默认加载
*/
defined('BY_JYA') or exit('error');
//扫码进入的
if($_RQ['fromuser'] && $_RQ['action']=='myhome'){
	$this->session('sao_fromuser',$_RQ['fromuser']);
}
cfc('core')->checklogin();
$return['pluginset']=$this->plugin_setting('setting');
$return['team_tiaojians']=$this->team_tiaojians;
if($_RQ['action']!='myhome'){
if($_RQ['is_access'] && $_RQ['action']!='apply' && $_RQ['action'] !='myshop' && $_RQ['action'] !='info'){
	$member=$this->model('member')->checkmember('',true);
}else{
	$member=$this->model('member')->checkmember('',false);
}
if($_SESSION['container']=='wxapp' && !$_SESSION['fromh5wxapp']){
	$iswxapp=1;
}
if(($_RQ['is_access'] || $iswxapp) && (!$member['is_agent'] || $member['stop']) && $_RQ['action'] !='myshop'  && $_RQ['action'] !='apply'){
	//还不是分销商，跳转申请页
	$return['applystatus']=$this->getcolumn('team',array('mid'=>$_SESSION['uid']),'status');
	if($return['applystatus']==1 && $member['is_agent']!=1){
		pdo_delete('jy_carfee_team',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	}
	$apply=$this->get('team',array('mid'=>$_SESSION['uid']),array('id','remark'));
	if($apply['id']){
		$return['apply']=$apply;
		$return['applystatus']=$this->getcolumn('team',array('mid'=>$_SESSION['uid']),'status');
	}
	$apply=$this->getcolumn('team',array('mid'=>$_SESSION['uid']),'id');
	//判断是否满足申请分销商条件
	$can_apply=true;
	$return['desc']=$member['desc'];
	$return['now']=$member['now'];
	$return['limit']=$member['limit'];
	$return['unit']=$member['unit'];
	$return['can_apply']=$member['can_apply'];
	$return['become_goods']=$member['become_goods'];
	foreach($return['become_goods'] as &$gv){
		$gv['price']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['id']),'price');
	}
	$return['member']=$member;
	if($member['agent_id']){
		$return['agent']=model('core/member')->detail($member['agent_id'],array('nickname','avatar'));
		$return['agent_name']=$return['agent']['nickname'];
	}
	$return['htmls']=$this->template_url('apply');
	$setting=$this->plugin_setting('page_setting');
	set_html('title',$setting['tcenter']);
	$return['setting']=$setting;
	$return['setapply']=$this->plugin_setting('apply');
	$return['item']=model('core/member')->detail($_SESSION['uid'],array('nickname','avatar','realname','mobile','wechat'));
	if($iswxapp){		
		exi('','','jy_carfee/apply/');
	}
	exi($return);
}
}

